﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace Taobao.Tools
{
    public partial class ConfigurationForm : Form
    {
        public ConfigurationForm()
        {
            InitializeComponent();
        }

        private void ConfirmButton_Click(object sender, EventArgs e)
        {
            Configuration.PreparingOperation = PrepareCheckBox.Checked;
            Configuration.SentBeforeAllAction = SentBeforeAllCheckBox.Checked;
            Configuration.GetRefunds = GetRefundsCheckBox.Checked;
            Configuration.GetTrades = GetTradesCheckBox.Checked;
            Configuration.GetTradesInfo = GetTradesInfoCheckBox.Checked;
            Configuration.UpdateTradesInfo = UpdateTradeInfoCheckBox.Checked;
            Configuration.Sent = SentCheckBox.Checked;
            Configuration.WaitBuyerPay = WaitBuyerPayCheckBox.Checked;
            Configuration.WaitSellerSendGoods = WaitSellerSendCheckBox.Checked;
            Configuration.TradeNoCreatePay = WaitCreatePayCheckBox.Checked;
            ToolConfiguration.Save(Configuration);
            if (MessageBox.Show("保存新的配置成功，需要重启程序才能使配置生效!\n 是否关闭当前程序？", "", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK)
            {
                var currentProcess = Process.GetCurrentProcess();
                var startInfo = currentProcess.StartInfo;
                Process.GetCurrentProcess().Kill();
            } 
        }

        private void CancelButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private ToolConfiguration Configuration = null;
        private void ConfigurationForm_Load(object sender, EventArgs e)
        {
            Configuration = ToolConfiguration.Load();
            PrepareCheckBox.Checked = Configuration.PreparingOperation;
            SentBeforeAllCheckBox.Checked = Configuration.SentBeforeAllAction;
            GetRefundsCheckBox.Checked = Configuration.GetRefunds;
            GetTradesCheckBox.Checked = Configuration.GetTrades;
            GetTradesInfoCheckBox.Checked = Configuration.GetTradesInfo;
            UpdateTradeInfoCheckBox.Checked = Configuration.UpdateTradesInfo;
            SentCheckBox.Checked = Configuration.Sent;
            WaitBuyerPayCheckBox.Checked = Configuration.WaitBuyerPay;
            WaitSellerSendCheckBox.Checked = Configuration.WaitSellerSendGoods;
            WaitCreatePayCheckBox.Checked = Configuration.TradeNoCreatePay;
        }
    }
}
